//
//  GlobalData.m
//  MexicoLoan
//
//  Created by WXP on 2025/2/24.
//
//

#import "GlobalData.h"

UINavigationController * Global_Nav = nil;

@implementation GlobalData

@synthesize Global_Token = _Global_Token;
@synthesize Global_UserCode = _Global_UserCode;
@synthesize Global_ModelUser = _Global_ModelUser;

SYNTHESIZE_SINGLETONE_FOR_CLASS(GlobalData);

- (instancetype)init{
    self = [super init];
    if (self) {
        self.statusBarStyle = UIStatusBarStyleDefault;
    }
    return self;
}

#pragma mark - set/get
- (void)setGlobal_ModelUser:(ModelUser *)Global_ModelUser{
    [GlobalMethod writeStr:Global_ModelUser != nil?[GlobalMethod exchangeModelToJson:Global_ModelUser]:@"" forKey:LOCAL_USERMODEL];
    _Global_ModelUser = Global_ModelUser;
}
- (ModelUser *)Global_ModelUser{
    if (!isStr(_Global_ModelUser.phone)) {
        NSDictionary * dicItem = [GlobalMethod exchangeStringToDic:[GlobalMethod readStrFromUserDefaults:LOCAL_USERMODEL]];
        _Global_ModelUser = [ModelUser modelObjectWithDictionary:dicItem];
    }
    return _Global_ModelUser;
}

- (void)setGlobal_Token:(NSString *)Global_Token{
    [GlobalMethod writeStr:Global_Token != nil ? Global_Token : @"" forKey:LOCAL_TOKEN];
    _Global_Token = Global_Token;
}
- (NSString*)Global_Token{
    if (!isStr(_Global_Token)){
        _Global_Token = [GlobalMethod readStrFromUserDefaults:LOCAL_TOKEN];
    }
    return _Global_Token;
}

- (void)setGlobal_UserCode:(NSString *)Global_UserCode{
    [GlobalMethod writeStr:Global_UserCode != nil ? Global_UserCode : @"" forKey:LOCAL_USERCODE];
    _Global_UserCode = Global_UserCode;
}
- (NSString*)Global_UserCode{
    if (!isStr(_Global_UserCode)){
        _Global_UserCode = [GlobalMethod readStrFromUserDefaults:LOCAL_USERCODE];
    }
    return _Global_UserCode;
}

#pragma mark - lazy
- (NoticeView *)Global_NoticeView{
    if (_Global_NoticeView == nil) {
        _Global_NoticeView = [NoticeView new];
    }
    return _Global_NoticeView;
}

@end
